/**
 * 门诊简易挂号
 */
	 var nianlianchusheng;
	 var nianlianjisuan;
	 var leibiefeibie=0;
function guahao()
{
	debugger;
	$.ajax(
			{
			type : 'get',
			url : rootUrl + "/clidoctor/selectDataByScriptId?ID=7263",
			dataType : "json",
			success : function(data)
			{
				if(data){
				laytplUrl(myurl + "/module/menzhen_guahao.html",data, function(data, html)
						{
					var index = layer.open({
								type : 1,
								// scrollbar : false,
								title : "简易挂号",
								area :
									["80%", "80%"],
									shade : 0.1,
									maxmin : true,
									content : html,
									closeBtn : 1,
									success : function()
									{
										$("select").select2({})
										$("#remove_guahao").on("click", function()
												{
											layer.close(index);
												});
										guahaoinit();// 初始化input 和select
										hideAllDiv();
									}
							})
							
						});
				}
			}
		})
}

function guahaoinit()
{
	findInputEvent(); // input
	loadbdp02(); // 病人类别
	addaat02(); // 职业信息
	addack02(); // 婚姻状况
	addacc02(); // 国籍信息
	addabq02(); // 民族信息
	addabj02();// 医疗付款方式
	adduaa03(); // 获取社区
	addbdx02(); // 获取了解途径
	// addbah03(); //获取疾病分类
	loadbcb01();//
	addabu19();//获取住址
	loadbaq01();//获取工作单位
//	loadSysParm();
}

/*
 * 加载病人类别
 */
function loadbdp02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 4169,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#bdp02").empty();
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].bdp02).text(json.list[i].bdp02);
				$("#bdp02").append(option);
			}
			loadabc02($("#bdp02"));
		}
	});
}
// 获取职业的信息
function addaat02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 616,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#vac16").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#vac16").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].aat01).text(json.list[i].aat02);
				$("#vac16").append(option);
			}
		}
	});
}
// 获取婚姻的信息
function addack02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 593,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#ack01").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#ack01").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].ack01).text(json.list[i].ack02);
				$("#ack01").append(option);
			}
		}
	});
}

// 获取国籍的信息
function addacc02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 549,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#acc02").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#acc02").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].acc02).text(json.list[i].acc02);
				$("#acc02").append(option);
			}
		}
	});
}
// 获取民族的信息
function addabq02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 39,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#abq02").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#abq02").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].abq02).text(json.list[i].abq02);
				$("#abq02").append(option);
			}
		}
	});
}
// 获取医疗付款方式
function addabj02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 553,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#abj01").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#abj01").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].abj01).text(json.list[i].abj02);
				$("#abj01").append(option);

			}
		}
	});
}
// 获取社区
function adduaa03()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 2001,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#uaa01").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#uaa01").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].uaa01).text(json.list[i].uaa03);
				$("#uaa01").append(option);
			}
		}
	});

}
// 获取了解途径
function addbdx02()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 617,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#bdx02").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#bdx02").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].bdx02).text(json.list[i].bdx02);
				$("#bdx02").append(option);

			}
		}
	});
}
// 获取疾病分类
function addbah03()
{
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",
	{
	ID : 5250,
	paramStr : '{}'
	}, function(json)
	{
		if (json.result == "Success")
		{
			$("#bah03").empty();
			var option = $("<option>").val(0).text("--请选择--");
			$("#bah03").append(option);
			for (var i = 0; i < json.list.length; i++)
			{
				var option = $("<option>").val(json.list[i].bah03).text(json.list[i].bah03);
				$("#bah03").append(option);
			}
		}
	});
}
// 加载挂号挂别的信息
function loadbcb01()
{
	var bcb01td;
	$("#bcb03")
			.on('click', function()
			{
				
				var bce03flag = false;
				$("#bcb03").val("");
				$('#bck03').val("");
				$('#bce03').val("");
				var selectleft = $(this).parent().parent().position().left;
				var selecttop = $(this).parent().parent().position().top;
				$.get(rootUrl + "/clidoctor/selectDataByScriptId",
						{
						ID : 1878,
						paramStr : '{CurrTime:"' + getcurrentDate() + '",DateNum:"' + getWeek() + '",ltime:"' + gettime() + '",Date:"' + getcurrDate() + '"}'
						}, function(json)
						{
							if (json.result == "Success")
							{
								$("#layercover").removeClass("hidden");
								$("#bcb01html").css(
								{
								left : selectleft + 'px',
								top : selecttop + 30 + 'px'
								}).slideDown(300);
								$('#bcb01html').find("tbody tr").remove();
								bcb01td = "";
								for (var i = 0; i < json.list.length; i++)
								{
									var bcb01 = json.list[i].bcb01;
									if (bcb01 == undefined)
										bcb01 = "";
									var bcb03 = json.list[i].bcb03;
									if (bcb03 == undefined)
										bcb03 = "";
									var bao02 = json.list[i].bao02;
									if (bao02 == undefined)
										bao02 = "";
									var bck03 = json.list[i].bck03;
									if (bck03 == undefined)
										bck03 = "";
									var bce03 = json.list[i].bce03;
									if (bce03 == undefined)
										bce03 = "";
									var bby05 = json.list[i].bby05;
									if (bby05 == undefined)
										bby05 = "";
									bcb01td += "<tr>" + "<td  hidden='true'>" + bcb01 + "</td>" + "<td>" + bcb03 + "</td>" + "<td>" + bao02 + "</td>" + "<td>" + bck03 + "</td>" + "<td>" + bce03 + "</td>" + "<td>" + bby05 + "</td>" + "<td  hidden='true'>" + json.list[i].bce01 + "</td>" + "<td hidden='true'>" + json.list[i].bck01 + "</td>" + "</tr>";
								}
							}
							$('#bcb01html tbody').append(bcb01td);
							$('#bcb01html tbody tr').on('click', function()
							{
								debugger;
								$("#bcb01").val($(this).find("td").eq(0).html());
								$("#bcb03").val($(this).find("td").eq(1).html());
								$('#bck03').val($(this).find("td").eq(3).html());
								$('#bce03').val($(this).find("td").eq(4).html());
								$('#bck01').val($(this).find("td").eq(7).html());
								$("#bce01").val($(this).find("td").eq(6).html());
								gridxiangmu($(this).find("td").eq(0).html(), -1);
								selectbcb01 = $(this).find("td").eq(0).html();
								$.get(rootUrl + "/clidoctor/selectDataByScriptId",
								{
								ID : 5253,
								paramStr : '{BCB01:' + selectbcb01 + '}'
								}, function(json)
								{
									if (json.result == "Success")
									{
										if (json.list.length > 0)
										{
											$('#bck03').val(json.list[0].bck03);
											$('#bck01').val(json.list[0].bck01);
											loadbck03(selectbcb01);
											bce03flag = true;
										}
										else
										{

											loadbck01();
										}
									}
								});
								var boxes = document.getElementsByName('vac31');
								for (var i = 0; i < boxes.length; i++)
								{
									boxes[i].checked = false;
								}
								debugger;
								$(".selectTab").slideUp(300);
								$("#layercover").removeClass("hidden");
								$("#vaa03")[0].value = "";
								getvaa03();

							})
						});

			})

}
//加载费用项目的数据
function  gridxiangmu(bcb01,vac31){

	$('#xiangmu_info_content').resize(function(){
		$("#xiangmu_info_table").setGridWidth($("#xiangmu_info_content").width()*1);
	});
	jQuery("#xiangmu_info_table").jqGrid(
	          {
	        	url : rootUrl + "/clidoctor/commonQuery",
	        	postData:{ID : 1880,paramStr : "{BBY31:" + ShowMessage() + ",BCB01:" + bcb01 + "}"}, 
	            datatype : "json",
	            colNames:['选择','项目','金额','费目','bby01','bcf01','selected1'],
	            colModel:[ //这一项比较重要， 其中的name属性主要是用于后期的页面代码（注意这里的范围是本页面上的代码，不会涉及到后台代码）， 而index属性是则是用于涉及后台时，给后台传递排序字段 
	                   {name:'selected',index:'selected',width:60,align:'center',edittype:'checkbox',formatter:
	                	   function(v,x,r){
	                	  
	                	  
		                	   if(v==1){
		                   		   return "<input type='checkbox' checked='true' onchange='changeselect(this,"+x.rowId+");'/>";
		                   	   }else{
		                   		   return "<input type='checkbox' checked='false' onchange='changeselect(this,"+x.rowId+");'/>";
		                   	   }
	                	   }
	                   },
	                   {name:'bby05',index:'bby05',editable:true}, //sortable是该字段是否排序      //colModel两个最主要就是1:name前台js用,2:index给后台传递排序字段 
	                   {name:'bby25',index:'bby25',editable:true}, 
	                   {name:'bcf03',index:'bcf03',editable:true},
	                   {name:'bby01',index:'bby01',editable:true,hidden:true}, 
	                   {name:'bcf01',index:'bcf01',editable:true,hidden:true},
	                   {name:'selected1',index:'selected1',editable:true,hidden:true,formatter:
	                	  function(v,x,r){
	                	   if(v==undefined || v==1){
	                   		   return 1;
	                   	   }else{
	                   		   return 0;
	                   	   }
                	   }}
	                   ],
	                   multiselect: false,
	                   height : 'auto',
		       			width : '100%',
		       			autowidth : true,
		       			forceFit:true,
		       		    shrinkToFit:true,
	                   rownumbers:true,
	                   gridComplete : function() {
	                	 
//	                	   var boxes=document.getElementsByName('vac31');
//	              		    if(vac31==3){
//	              		        boxes[0].checked=true;
//	              		        boxes[1].checked=true;
//	              		        changeVac31delete();
//	              		        changeCarddelete(); 
//	              		    }else if(vac31==1){
//	              		    	boxes[0].checked=true;
//	              		    }else if(vac31==2){
//	              		    	 boxes[1].checked=true;
//	              		    }else if(vac31==0){
//	              		    	boxes[0].checked=false;
//	              		    	boxes[1].checked=false;
//	              		    }
//	                	   sumMoney();
	                     },

	          }
	     	
	      )
        jQuery("#xiangmu_info_table").jqGrid('setGridParam',{
		           url : rootUrl + "/clidoctor/commonQuery",
		           datatype : 'json',
		           //发送数据  
		           postData:{ID : 1880,paramStr : "{BBY31:" + ShowMessage() + ",BCB01:" + bcb01 + "}"},
		           page : 1,          
		           rownumbers:true
		        }).trigger('reloadGrid');//重新载入
	}
function ShowMessage()

{
	var today = new Date();
	var day = today.getDate();
	//获取当前日
	var month = today.getMonth() + 1;
	//显示月份比实际月份小
	var year = today.getFullYear();
	//获取完整的年份
	month = month < 10 ? "0" + month : month;
	//数字
	day = day < 10 ? "0" + day : day;
	var date = year + "-" + month + "-" + day;

	return date;

}
function getcurrentDate()

{
	var today = new Date();
	var day = today.getDate();
	// 获取当前日
	var month = today.getMonth() + 1;
	// 显示月份比实际月份小
	var year = today.getFullYear();
	var hour = today.getHours();
	var minute = today.getMinutes();
	var second = today.getSeconds();

	// 获取完整的年份
	hour = hour < 10 ? "0" + hour : hour;
	minute = minute < 10 ? "0" + minute : minute;
	month = hour < 10 ? "0" + month : month;
	second = second < 10 ? "0" + second : second;
	// 数字
	day = day < 10 ? "0" + day : day;
	var date = year + "-" + month + "-" + day + " " + hour + "^" + minute + "^" + second;

	return date;

}
function getWeek()

{
	var today = new Date();
	var day = today.getDay();

	return day + 1;

}
function gettime()
{
	var today = new Date();
	var h = today.getHours(); // 获取系统时
	if (h < 10)
	{
		h = "0" + h;
	}
	var m = today.getMinutes(); // 分
	if (m < 10)
	{
		m = "0" + m;
	}
	var s = today.getSeconds(); // 秒
	if (s < 10)
	{
		s = "0" + s;
	}
	var mytime = h + "^" + m + "^" + s;
	return mytime;
}
function getcurrDate()

{
	var today = new Date();
	var day = today.getDate();
	// 获取当前日
	var month = today.getMonth() + 1;
	// 显示月份比实际月份小
	var year = today.getFullYear();
	// 获取完整的年份

	month = month < 10 ? "0" + month : month;

	// 数字
	day = day < 10 ? "0" + day : day;
	var date = year + "-" + month + "-" + day + " " + "00" + "^" + "00" + "^" + "00.000";

	return date;

}
//获取门诊号
function getvaa03(){
	var url=rootUrl + "/clidoctor/getvaa03";
	  $.ajax({
          url:url,
          type:"get",
          dataType:"json",
          async: false, 
          cache:false,
          success:function(json){
        	  if(json.result=="SUCCESS"){
        		$("#vaa03_1").val(json.list[0].VAA03);
      			$("#vaa03").val(json.list[0].VAA03);
      		}
          }
      });
}

//加载科室信息

function loadbck03(bcb01){
	if(selectbcb01!= bcb01)return;
	var bck03td;
	var flag=true;
	$("#bck03").on('click',function(){
		if(selectbcb01!= bcb01){
			loadbck01();
			return;
		}
		$('#bck03html').find("tbody tr").remove();
		var selectleft=$(this).offset().left-210;
		var selecttop=$(this).offset().top-118;
		$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:5253,paramStr:'{BCB01:'+ selectbcb01 + '}'}, function(json){
			if(json.result=="Success"){
				$('#bck03html table').css("width","100%");
				$("#bck03html").css({left:selectleft+'px',top:selecttop+30+'px'}).slideDown(300);
				$('#bck03html').find("tbody tr").remove();
				 bck03td = "";
					 for(var i=0;i<json.rows.length;i++){
						    var bck02=json.rows[i].bck02;
						    if(bck02==undefined) bck02="";
						    var bck03=json.rows[i].bck03;
						    if(bck03==undefined) bck03="";
						    bck03td +="<tr>"+
							"<td>"+bck02+"</td>"+
							"<td>"+bck03+"</td>"+
							"<td  hidden='true'>"+json.rows[i].bck01+"</td>"+
							"</tr>";
						}
					}
				 $('#bck03html tbody').append(bck03td);
				 $('#bck03html tbody tr').on('click',function(){
						$('#bck03').val($(this).find("td").eq(1).html());
						$('#bck01').val($(this).find("td").eq(2).html());
						
			    	})
		});
		
	})
	 $.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:5254,paramStr:'{BCB01:'+ bcb01 + '}'}, function(json){
			if(json.result=="Success"){
				if(json.rows.length>0){
						$('#bce03').val(json.rows[0].bce03);
						$('#bce01').val(json.rows[0].bce01);
						if(selectbcb01 == bcb01){
						   loadbce03(selectbcb01);
						}
				}
			}
		});
}

function loadbce03(bcb01){

	if(selectbcb01!= bcb01)return;
	var bce03td;
	$("#bce03").on('click',function(){
		if(selectbcb01!= bcb01){
			loadbce01();
			return;
		}
		$('#bce03html').find("tbody tr").remove();
		var selectleft=$(this).offset().left-210;
		var selecttop=$(this).offset().top-118;
		$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:5254,paramStr:'{BCB01:'+ selectbcb01 + '}'}, function(json){
			if(json.result=="Success"){
				$('#bce03html table').css("width","100%");
				$("#bce03html").css({left:selectleft+'px',top:selecttop+30+'px'}).slideDown(300);
				bce03td="";
				 $('#bce03html').find("tbody tr").remove();
				   for(var i=0;i<json.rows.length;i++){
					    var bce02=json.rows[i].bce02;
					    if(bce02==undefined) bce02="";
					    var bce03=json.rows[i].bce03;
					    if(bce03==undefined) bce03="";
					    var bce04=json.rows[i].bce04;
					    if(bce04==undefined) bce04="";
					    var aah02=json.rows[i].aah02;
					    if(aah02==undefined) aah02="";
					    bce03td +="<tr>"+
						"<td>"+bce02+"</td>"+
						"<td>"+bce03+"</td>"+
						"<td>"+bce04+"</td>"+
						"<td>"+aah02+"</td>"+
						"<td  hidden='true'>"+json.rows[i].bce01+"</td>"+
						"</tr>";
					}
				}
				$('#bce03html tbody').append(bce03td);
				$('#bce03html tbody tr').on('click',function(){
				$('#bce03').val($(this).find("td").eq(1).html());
				$('#bce01').val($(this).find("td").eq(4).html());
		    	})
		});
		
	})

}
//加载费别的信息
function loadabc02(obj){
	$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:5240,paramStr:'{BDP02:"'+$(obj).find("option:selected").text()+'"}'}, function(json){
		if(json.result=="Success"){
			for(var i=0;i<json.rows.length;i++){
				$("#abc02").val(json.rows[i].abc02);
			}
		}
	});
}

//复诊赋值
function checkvac06(obj) {
	if ($(obj).html()=="是") {
		$("#vac06_1").removeClass("btn-white").addClass("btn-grey");
		$("#vac06_2").removeClass("btn-grey").addClass("btn-white");
		$("#vac06").val(1);
	} else {
		$("#vac06_1").removeClass("btn-grey").addClass("btn-white");
		$("#vac06_2").removeClass("btn-white").addClass("btn-grey");
		$("#vac06").val(0);
	}
	
}
//急诊赋值
function checkvac10(obj) {
	if ($(obj).html()=="是") {
		$("#vac10_1").removeClass("btn-white").addClass("btn-grey");
		$("#vac10_2").removeClass("btn-grey").addClass("btn-white");
		$("#vac10").val(1);
	} else {
		$("#vac10_1").removeClass("btn-grey").addClass("btn-white");
		$("#vac10_2").removeClass("btn-white").addClass("btn-grey");
		$("#vac10").val(0);
	}
}
//是否查看健康档案赋值
function checkvcj15(obj) {
	if ($(obj).html()=="是") {
		$("#vcj15_1").removeClass("btn-white").addClass("btn-grey");
		$("#vcj15_2").removeClass("btn-grey").addClass("btn-white");
		$("#vcj15").val(1);
	} else {
		$("#vcj15_1").removeClass("btn-grey").addClass("btn-white");
		$("#vcj15_2").removeClass("btn-white").addClass("btn-grey");
		$("#vcj15").val(0);
	}
}

/**
 * 保存挂号信息
 */
 function saveGuahao()
 {
	 var n = /^[0-9]*[1-9][0-9]*$/;// 正整数；
	 var url = rootUrl + "/cliregistration/save";
	 //挂号数据
	 var bck01Obj = {name:"lBCK01",value:bck01};
	 var vac45Obj = {name:"lVAC45",value:1};
	 var bce01Obj = {name:"lBCE01",value:bce01};
	 var bce02Obj = {name:"lBCE02A",value:loginName};
	 var bce03Obj = {name:"lBCE03A",value:bce03};
	 var data1 = $("#saveGuahao").serializeArray(); 
	 data1.push(bck01Obj);
	 data1.push(vac45Obj);
	 data1.push(bce01Obj);
	 data1.push(bce02Obj);
	 data1.push(bce03Obj);
	 console.log(data1);
	 debugger
	 var vaa03 = {};vaa03.value=$("#vaa03").val()?true:false; 
	 var vaa05 = {};vaa05.value=$("#gh_vaa05").val()?true:false;
	 var abw01 = {};abw01.value=$("#abw01").val()?true:false;
	 var vaa12 = {};vaa12.value=$("#vaa12").val()?true:false;
	 var vaa10 = {};vaa10.value=$("#vaa10").val()?true:false;
	 var bdp02 = {};bdp02.value=$("#bdp02").val()?true:false;
	 var abc02 = {};abc02.value=$("#abc02").val()?true:false;
	 var bcb01 = {};bcb01.value=$("#bcb01").val()?true:false;
	 vaa03.msg="门诊号";
	 vaa05.msg="姓名";
	 abw01.msg="性别";
	 vaa12.msg="出生日期";
	 vaa10.msg="年龄";
	 bdp02.msg="病人类别";
	 abc02.msg="病人费别";
	 bcb01.msg="挂号类别";
	 var arr = [];
	 arr.push(vaa03);
	 arr.push(vaa05);
	 arr.push(abw01);
	 arr.push(vaa12);
	 arr.push(vaa10);
	 arr.push(bdp02);
	 arr.push(abc02);
	 arr.push(bcb01);
	var msg = '';
	$(arr).each(function(i,ele){
		if(!ele.value){
			msg += ele.msg + "不能为空<br/>" ;
		}
	})
	if(msg)
	{
		layer.alert(msg,{title:'!!!警告'});
		return;
	}
	if (!n.test($("#vaa10").val())){
		layer.alert("请输入正确的年龄！");
		return;
	}
	 var mydata = JSON.stringify(data1); 
	 //费用数据
	 var grid2 = $("#xiangmu_info_table").jqGrid("getRowData");
	 for(var i = 0;i<grid2.length;i++)
	 {
		 grid2[i].vaj25 = 1;
		 grid2[i].vaj30 = 100;
		 grid2[i].vaj31 = 100;
		 grid2[i].vaj33 = grid2[i].bby25;
		 grid2[i].vaj36 = grid2[i].bby25;
		 grid2[i].vaj37 = grid2[i].bby25;
	 }
	 var grid2rows = JSON.stringify(grid2);
	 
	 $.ajax({url:url,
		 data:{"mydata":mydata,"grid2rows":grid2rows},
		 type:"post",
		 dataType:"json",
		 success:function(data){
			 if(data.result=="Success")
			 {
				 layer.alert("保存成功");
			 }
			 else
			 {
				 layer.alert("保存失败");
			 }
	 }});
 }

 function getBirthDayByAge(obj){ 
 	var fiFlag=false;
 	var nowDate=new Date().Format("yyyy-MM-dd hh:mm:ss");
 	var intBeginYear = parseInt(nowDate.substring(0, 4),10); 
     var intBeginMonth = parseInt(nowDate.substring(nowDate.indexOf("-") + 1, nowDate.indexOf("-") + 3),10);  
     var intBeginDate = parseInt(nowDate.substring(nowDate.lastIndexOf("-") + 1, nowDate.lastIndexOf("-") + 3),10); 
     var age=0;
     if(obj==undefined){
     	age=$("#vaa10").val();
     }else{
     	age=$(obj).val();
     }
 	//var age=$(obj).val();
 	var result=0;
 	var monthresult=0;
    var monthDef = Math.round(12*age);  
    if($("#aau01").val()=="Y"){
 	   	$("#vaa12").val(getBirthday(nowDate,monthDef,fiFlag));  
    }else if($("#aau01").val()=="D"){
 	    result=$("#vaa10").val()-intBeginDate;
 	    if(result>=0){
 	    	$("#vaa12").val(intBeginYear+"-"+intBeginMonth+"-"+result+" 00:00:00"); 
 	    }else{
 	    	intBeginMonth=intBeginMonth-1;
 	    	result=intBeginMonth*30-result;
 	    	$("#vaa12").val(intBeginYear+"-"+intBeginMonth+"-"+result+" 00:00:00"); 
 	    }
    }else if($("#aau01").val()=="M"){
 	    monthresult=intBeginMonth-$("#vaa10").val();
 	    if(monthresult>=0){
 	    	$("#vaa12").val(intBeginYear+"-"+monthresult+"-"+intBeginDate+" 00:00:00");
 	    }else{
 	    	if($("#vaa10").val()<=12){
 	    		intBeginYear=intBeginYear-1;
 	    		monthresult=intBeginMonth+12-$("#vaa10").val();
 	    		$("#vaa12").val(intBeginYear+"-"+monthresult+"-"+intBeginDate+" 00:00:00");
 	    	}else{
 	    		intBeginYear=intBeginYear-parseInt($("#vaa10").val()/12);
 	    		monthresult=parseInt($("#vaa10").val()/12)*12+parseInt($("#vaa10").val()%12)-intBeginMonth;
 	    		$("#vaa12").val(intBeginYear+"-"+monthresult+"-"+intBeginDate+" 00:00:00");
 	    	}
 	    	
 	    }
 	   	//$("#vaa12").val(getBirthday(nowDate,monthDef,fiFlag));  
    }
}
 function getMonthMaxDay(year, month) {  
     if (month == 4 || month == 6 || month == 9 || month == 11) {  
           return 30;  
     } else if (month != 2) {  
           return 31;  
     } else {  
          if (year % 4 == 0 || (year % 100 == 0 && year % 400 == 0)) {  
            if (month == 2) {  
                      return 29;  
         }  
            } else {  
                  if (month == 2) {  
                      return 28;  
             }  
             }  
        }  
     return 0;  
     }


 /** 
  * 跟据月龄推算生日 
   */  
  function getBirthday(nowDate,monthDef,fiFlag){  
     var intBeginYear = parseInt(nowDate.substring(0, 4),10);  
          //从"-"后截取月数  
      var intBeginMonth = parseInt(nowDate.substring(nowDate.indexOf("-") + 1, nowDate.indexOf("-") + 3),10);  
   var intBeginDate = parseInt(nowDate.substring(nowDate.lastIndexOf("-") + 1, nowDate.lastIndexOf("-") + 3),10);  
  //年差推算年份  
   var yearBet = parseInt(monthDef/12,10);  
     var year = intBeginYear - yearBet  
   //月差推算月份  
      var monthBet = monthDef%12;  
      var month = intBeginMonth-monthBet;  
    if(month <= 0){  
         year-=1;  
       month+=12;  
      }  
      //算日期范围 -15  
      var date1 = intBeginDate - 15;  
   var year1 = year;  
      var month1 = month;  
     //如果-15的天数小于0，那么月份向后退一个月，如果月份退后也小于等于0，那么年份后退一年  
      if(date1 < 0){  
        month1 = parseInt(month1,10) - 1;  
         if(month <= 0){  
              year1-=1;  
             month1+=12;  
         }  
          var maxDate = getMonthMaxDay(year1,month1);  
        date1 += maxDate;  
     }else if(date1 == 0){  
         month1 = parseInt(month1,10) - 1;  
          if(month <= 0){  
             year1-=1;  
              month1+=12;  
         }  
         var maxDate = getMonthMaxDay(year1,month1);  
         date1 = maxDate;  
     }  
      if(parseInt(date1,10) < 10){  
           date1 = '0' + parseInt(date1,10);  
          }  
         if(parseInt(month1,10) < 10){  
              month1 = '0' + parseInt(month1,10);  
          }  
   var resultDate1 = year1+"-"+intBeginMonth+"-"+intBeginDate+" 00:00:00";  
       
     //算日期范围+15  
      var date2 = intBeginDate + 15;  
   var year2 = year;  
      var month2 = month;  
      var maxDate2 = getMonthMaxDay(year2,month2);  
      //如果+15天后日期大于本月的最大日期，那么月份向前推一个月，如果月份推后大于12，那么年份向前推一年，月份取1  
      if(date2 > maxDate2){  
          date2 = date2 - maxDate2;  
          month2 += 1;  
          if(month2 > 12){  
             month2 = month2 - 12;  
              year2 += 1;  
         }else if(month2 == 12){  
            month2 = 1;  
              year2 += 1;  
      }  
     }else if(date2 == maxDate2){  
        date2 = maxDate2;  
     }  
      if(parseInt(date2,10) < 10){  
             date2 = '0' + parseInt(date2,10);  
        }  
         if(parseInt(month2,10) < 10){  
              month2 = '0' + parseInt(month2,10);  
        }  
       
     var resultDate2 = year2+"-"+intBeginMonth+"-"+intBeginDate+" 00:00:00";  
        
      if(fiFlag){  
          return resultDate1;  
     }else{  
          return resultDate2;  
      }  

  }  

  
  /** 
   * 计算年龄 
   */  
   function yearDef(obj){  
  	 $("#aau01").val("Y");
  	 loadcommonsettingvalue();
   	var birthDayDate=$(obj).val();
   	if(birthDayDate!=""){
   		var nowDate=new Date().Format("yyyy-MM-dd hh:mm:ss");
   		var monthresult=monthDef(birthDayDate,nowDate);
   		var result=0;
   		if(monthresult>0){
   			result = parseInt(Math.round(monthresult / 12 * 10)/10); 
   			$("#vaa10").val(result);  
   		}else if(monthresult<0){
   			$("#vaa10").val(result);  
   		}
          
          
         
   	}
   	
   } 
 //加载公共参数
   function loadcommonsettingvalue(){
   	$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:16780,paramStr:'{ProductID:9999,ProgramID:9999,UserID:'+$.cookie('userId')+',BCKID:1,hostid:156}'}, function(json){
   		if(json.result=="Success"){
   			for(var i=0;i<json.rows.length;i++){
   				if(json.rows[i].paramno==58){
   					 nianlianjisuan=json.rows[i].value;
   				}else if(json.rows[i].paramno==18){
   					leibiefeibie=json.rows[i].value;
   				
   				}
   		     }
   	       }
     });
   	return leibiefeibie;
   }

   /** 
    * 计算月龄 
    *    
    */  
    function monthDef(birthDayDate,nowDate){  
        var intBeginYear = parseInt(birthDayDate.substring(0, 4));  
           //从"-"后截取月数  
    var intBeginMonth = parseInt(birthDayDate.substring(birthDayDate.indexOf("-") + 1, birthDayDate.indexOf("-") + 3),10);  
       var intBeginDate = parseInt(birthDayDate.substring(birthDayDate.lastIndexOf("-") + 1, birthDayDate.lastIndexOf("-") + 3),10);  
         
      var intEndYear = parseInt(nowDate.substring(0, 4));  
      var intEndMonth = parseInt(nowDate.substring(nowDate.indexOf("-") + 1, nowDate.indexOf("-") + 3),10);  
        var intEndDate = parseInt(nowDate.substring(nowDate.lastIndexOf("-") + 1, nowDate.lastIndexOf("-") + 3),10);  
         
       var year = (intEndYear - intBeginYear) * 12;  
       var month = intEndMonth - intBeginMonth;  
        var result = year + month - 1;  
       if(intEndDate - intBeginDate < 0 && getMonthMaxDay(intBeginYear, intBeginMonth) - intBeginDate + intEndDate >= 15){  
    	   if(nianlianjisuan=="1" && (intBeginMonth>intEndMonth || (intBeginMonth==intEndMonth && intBeginDate>intEndDate))){
    		   result = year + month - 1;  
               result = result;  
    	   }else{
    		   result = year + month - 1;  
               result = result + 1;  
    	 }
             
            }else if(intEndDate - intBeginDate < 0 &&getMonthMaxDay(intBeginYear, intBeginMonth) - intBeginDate + intEndDate < 15){  
               result = year + month - 1;  
              result = result;  
          }else if(intEndDate - intBeginDate > 0 &&intEndDate - intBeginDate  >= 15){  
              result = year + month;  
               result = result + 1;  
           }else if(intEndDate - intBeginDate > 0 &&intEndDate - intBeginDate  < 15){  
               result = year + month;  
               result = result;  
               if(result==0){
            	   $("#vaa10").val(intEndDate-intBeginDate);
            	   $("#aau01").val("D");
               }
           }  
            if(result ==undefined ){  
                result = 0;  
          }  
          return result;  
   }
    /*------------------------------------------------------检索-------------------------------------------------------*/

  //据据门诊号、姓名、五笔、拼音、身份证等进行检索病人信息
    function searchData(e) {
    	if (e.keyCode == 13 || e==undefined || e.keyCode==undefined) {
              var searchtd="";
              var searchKey = $("#searchKey").val();
      		var paramKey;
      		if (searchKey == "a.VAA03") {
      			paramKey = "VAA03";
      		} else if (searchKey == "a.VAA05") {
      			paramKey = "VAA05";
      		} else if (searchKey == "a.ABBRP") {
      			paramKey = "ABBRP";
      		} else if (searchKey == "a.VAA15") {
      			paramKey = "VAA15";
      		} else if (searchKey == "a.VAA02") {
      			paramKey = "VAA02";
      		} else if (searchKey == "a.VAA35") {
      			paramKey = "VAA35";
      		} else if (searchKey == "a.VAA84") {
      			paramKey = "VAA84";
      		}
    				var selectleft=$("#mzserach").parent().position().left;
    				var selecttop=$("#mzserach").parent().position().top;
    				$('#vaa05html').find("tbody tr").remove();
    				$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:997,paramStr:"{'"+paramKey+"':'%"+$("#mzserach").val()+"%'}"}, function(json){
    					if(json.result=="Success"){
    						$('#vaa05html table').css("min-width","600");
    						$("#layercover").removeClass("hidden");
    						$("#vaa05html").css({left:selectleft+'px',top:selecttop+30+'px'}).slideDown(300);
    						   for(var i=0;i<json.list.length;i++){
    							    var vaa05=json.list[i].vaa05;
    							    if(vaa05==undefined) vaa05="";
    							    var vaa10=json.list[i].vaa10;
    							    if(vaa10==undefined) vaa10="";
    							    var abw02=json.list[i].abw02;
    							    if(abw02==undefined) abw02="";
    							    var vaa03=json.list[i].vaa03;
    							    if(vaa03==undefined) vaa03="";
    							    var vaa04=json.list[i].vaa04;
    							    if(vaa04==undefined) vaa04="";
    							    var vaa15=json.list[i].vaa15;
    							    if(vaa15==undefined) vaa15="";
    							    var vaa35=json.list[i].vaa35;
    							    if(vaa35==undefined) vaa35="";
    							   
    							    searchtd +="<tr>"+
    								"<td>"+vaa05+"</td>"+
    								"<td>"+vaa10+"</td>"+
    								"<td>"+abw02+"</td>"+
    								"<td>"+vaa03+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vaa01+"</td>"+
    								"<td>"+vaa15+"</td>"+
    								"<td>"+vaa35+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bep06b+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vac57+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vac46+"</td>"+
    								"<td  hidden='true'>"+json.list[i].ack01+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bdp02+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bcb01a+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vac16+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bce03a+"</td>"+
    								"<td  hidden='true'>"+json.list[i].abc02+"</td>"+
    								/*"<td  hidden='true'>"+json.list[i].abc02+"</td>"+*/
    								"<td  hidden='true'>"+json.list[i].bck03+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bck01a+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bce01a+"</td>"+
    								"<td  hidden='true'>"+json.list[i].aau01+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vaa12+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vac06+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vac10+"</td>"+
    								"<td  hidden='true'>"+json.list[i].vac31+"</td>"+
    								"<td  hidden='true'>"+json.list[i].bcb03+"</td>"+
    								"<td  hidden='true'>"+json.list[i].abw01+"</td>"+
    								"</tr>";
    							}
    						}
    						    $('#vaa05html tbody').append(searchtd);
    						    $('#vaa05html tbody tr').on('click',function(){
    							$('#gh_vaa05').val($(this).find("td").eq(0).html());
    							$("#vaa10").val($(this).find("td").eq(1).html());
    					    	$("#abw02").val($(this).find("td").eq(25).html());
    					    	$("#vaa01").val($(this).find("td").eq(4).html());
    					    	$("#vaa03").val($(this).find("td").eq(3).html());
    					    	$("#vaa03_1").val($(this).find("td").eq(3).html());
    							$('#vaa15').val($(this).find("td").eq(5).html());
    							$('#vaa35').val($(this).find("td").eq(6).html());
    							$('#bep06b').val($(this).find("td").eq(7).html());
    							$('#vac57').val($(this).find("td").eq(8).html());
    							$('#vac46').val($(this).find("td").eq(9).html());
    							$('#ack01').val($(this).find("td").eq(10).html());
    							$('#bdp02').val($(this).find("td").eq(11).html()); 
    							$('#bcb01').val($(this).find("td").eq(12).html());
    							$('#vac16').val($(this).find("td").eq(13).html());
    							$('#bce03').val($(this).find("td").eq(14).html()); 
    							$('#abc02').val($(this).find("td").eq(15).html());
    							 $('#bck03').val($(this).find("td").eq(16).html());
    							 $('#bck01').val($(this).find("td").eq(17).html()); 
    						     $('#bce01').val($(this).find("td").eq(18).html());
    						     $('#aau01').val($(this).find("td").eq(19).html());
    							$('#bcb03').val($(this).find("td").eq(24).html());
    							var vaa12Value=$(this).find("td").eq(20).html();
    							if(vaa12Value != "undefined"){
    								 $('#vaa12').val(moment(vaa12Value).format("YYYY-MM-DD HH:mm:ss")); 
    							}else{
    							//	getBirthDayByAge();
    							}
    							selectbcb01=$(this).find("td").eq(12).html();
    							gridxiangmu($(this).find("td").eq(12).html(),$(this).find("td").eq(23).html());
    							$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:5253,paramStr:'{BCB01:'+ selectbcb01 + '}'}, function(json){
    								if(json.result=="Success"){
    									if(json.rows.length>0){
    										$('#bck03').val(json.rows[0].bck03);
    										$('#bck01').val(json.rows[0].bck01);
    										loadbck03(selectbcb01);
    										bce03flag=true;
    									}else{
    										
    										loadbck01();
    									}
    								}
    							});
    						    $('#vaa05html').slideUp().find("tbody tr").remove();
    						    $("#layercover").addClass("hidden");
    						    
    				    	})
    			
    				  
    			})
    	}
    		return false;
    						
    } 


function hideAllDiv(){
	$("#layercover").on("click",function(){
		$("#layercover").addClass("hidden");
		$('.selectTab').slideUp();
		
	})
}
//获取住址
function addabu19() {
	$("#vac19").on('click',function(){	
		var selectleft=$(this).parent().position().left;
		var selecttop=$(this).parent().position().top;
		$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:598,paramStr:'{LVLNR:3}'}, function(json){
			if(json.result=="Success"){
				//$('#abu09html table').css("width","100%");
				$("#layercover").removeClass("hidden");
				$("#abu09html").css({left:selectleft+'px',top:selecttop+30+'px'}).slideDown(300);
				$('#abu09html').find("tbody tr").remove();
				var abu09td = "";
				   for(var i=0;i<json.rows.length;i++){
					    var province=json.rows[i].province;
					    if(province==undefined) province="";
					    var area=json.rows[i].area;
					    if(area==undefined) area="";
					    var abu09=json.rows[i].abu09;
					    if(abu09==undefined) abu09="";
					    abu09td +="<tr>"+
						"<td>"+province+"</td>"+
						"<td>"+area+"</td>"+
						"<td>"+abu09+"</td>"+
						"</tr>";
					}
				}
				$('#abu09html tbody').append(abu09td);
				$('#abu09html tbody tr').on('click',function(){
					$("#vac19").val($(this).find("td").eq(2).html()); 
					$("#vac17").val($(this).find("td").eq(0).html());
					$("#vac18").val($(this).find("td").eq(1).html());
					$("#layercover").addClass("hidden");
					$('#abu09html').slideUp();
		    	})
		});
		
	})
}
//获取工作单位
function loadbaq01(){
	$("#baq03").on('click',function(){
		var selectleft=$(this).parent().position().left;
		var selecttop=$(this).parent().position().top;
		$.get(rootUrl + "/clidoctor/selectDataByScriptId",{ID:600,paramStr:'{}'}, function(json){
			if(json.result=="Success"){
//				$('#baq01html table').css("width","100%");
				$("#baq01html").css({left:selectleft+'px',top:selecttop+30+'px'}).slideDown(300);
				$('#baq01html').find("tbody tr").remove();
				var baq03td = "";
				   for(var i=0;i<json.rows.length;i++){
					    var baq02=json.rows[i].baq02;
					    if(baq02==undefined) baq02="";
					    var baq03=json.rows[i].baq03;
					    if(baq03==undefined) baq03="";
					    baq03td +="<tr>"+
						"<td>"+baq02+"</td>"+
						"<td>"+baq03+"</td>"+
						"<td hidden='true'>"+json.rows[i].baq08+"</td>"+
						"<td hidden='true'>"+json.rows[i].baq10+"</td>"+
						"<td hidden='true'>"+json.rows[i].baq01+"</td>"+
						"</tr>";
					}
				}
				$('#baq01html tbody').append(baq03td);
				$('#baq01html tbody tr').on('click',function(){
					$("#baq03").val($(this).find("td").eq(1).html()); 
					$("#baq01").val($(this).find("td").eq(4).html());
					$("#vac26").val($(this).find("td").eq(0).html());
					$("#vac27").val($(this).find("td").eq(1).html());
					$("#vac28").val($(this).find("td").eq(2).html());
					$("#vac29").val($(this).find("td").eq(3).html());
					$("#layercover").addClass("hidden");
					$('#baq01html').slideUp();
		    	})
		});
		
	})
	
}






    /*------------------------------------------------------检索-------------------------------------------------------*/
// =========================================================页面设置====================================================
function setGuahao()
{
	laytplUrl(myurl + "/module/menzhen_set_guahao.html",
	{}, function(data, html)
	{
		var index = layer.open(
		{
		type : 1,
		// scrollbar : false,
		title : "界面设置",
		area :
		["40%", "80%"],
		shade : 0.1,
		// maxmin : true,
		content : html,
		closeBtn : 1,
		success : function()
		{
			$("select").select2(
			{
				language : "zh-CN"
			})
			$(".remove").on("click", function()
			{
				layer.close(index);
			});
			
			Inityemianshezhi();
			
		}
		})

	});
}

// 查询挂号号类的信息
function Inityemianshezhi()
{
	$('#jichu_set_container').resize(function()
	{
		$("#jichu_set_table").setGridWidth($("#jichu_set_container").width() * 1);
	});
	jQuery("#jichu_set_table")
			.jqGrid(
			{
			url : rootUrl + "/clidoctor/selectDataByScriptId",
			postData :
			{
			ID : 7263,
			paramStr : "{}"
			},
			datatype : "json",
			colModel :
			[
			{
			label : "显示",
			name : 'saveselected',
			index : 'saveselected',
			editable : true,
			hidden : true,
			align : 'center'
			},
			{
			label : "页面元素",
			name : 'description',
			index : 'description',
			editable : true,
			align : 'center'
			},
			
			{
			label : "必输项",
			name : 'savemustinput',
			index : 'savemustinput',
			align : 'center',
			editable : true,
			formatter : function(value, row, index)
			{
				if (value == 1)
				{
					return "<input type='checkbox' id='savemustinput" + index + "' checked='checked' onchange='changesavemustinput(this," + row.rowId + ");'/>";
				}
				else
				{
					return "<input type='checkbox' id='savemustinput" + index + "' onchange='changesavemustinput(this," + row.rowId + ");'/>";
				}
			}
			},
			{
				label : "允许编辑",
				name : 'savecanedit',
				index : 'savecanedit',
				align : 'center',
				editable : true,
				formatter : function(value, row, index)
				{
					if (value == 1)
					{
						return "<input type='checkbox' id='savecanedit" + index + "' checked='checked' onchange='changesavecanedit(this," + row.rowId + ");'/>";
					}
					else
					{
						return "<input type='checkbox' id='savecanedit" + index + "' onchange='changesavecanedit(this," + row.rowId + ");'/>";
					}
				}
				},
			{
			label : "productid",
			name : 'productid',
			index : 'productid',
			align : 'center',
			hidden : true
			},
			{
			label : "programid",
			name : 'programid',
			index : 'programid',
			align : 'center',
			hidden : true
			},
			{
			label : "paramno",
			name : 'paramno',
			index : 'paramno',
			align : 'center',
			hidden : true
			},
			{
			label : "name",
			name : 'name',
			index : 'name',
			align : 'center',
			hidden : true
			},
			{
			label : "privilege",
			name : 'privilege',
			index : 'privilege',
			align : 'center',
			hidden : true
			},
			{
			label : "pvalue",
			name : 'pvalue',
			index : 'pvalue',
			align : 'center',
			hidden : true
			},
			{
			label : "savecanedit1",
			name : 'savecanedit',
			index : 'savecanedit1',
			align : 'center',
			hidden : true
			},
			{
			label : "savemustinput1",
			name : 'savemustinput',
			index : 'savemustinput',
			align : 'center',
			hidden : true
			}],
			multiselect : true, // 是否支持多选
			multiboxonly : true,
			rownumbers : true,
			rowNum : 300,
			forceFit : true,
			shrinkToFit : true,
			autowidth : true,
			height : 'auto',
			width:'auto',
			gridComplete : function()
			{
				// $("#jqgh_jichu_set_table_cb").append("<span>显示</span>");
//				$("#jichu_set_table_cb").css("width", "75px");
//				$("#jichu_set_table tbody").find("td").eq(1).css("width", "75px");
				var rowIds = jQuery("#jichu_set_table").jqGrid('getDataIDs');
				for (var k = 0; k < rowIds.length; k++)
				{
					var curRowData = jQuery("#jichu_set_table").jqGrid('getRowData', rowIds[k]);
					var curChk = $("#" + rowIds[k] + "").find(".cbox");
					curChk.attr('name', 'checkboxname'); // 给每一个checkbox赋名字
					curChk.attr('value', curRowData['saveselected']); // 给checkbox赋值
					curChk.attr('title', curRowData['description']); // 给checkbox赋予额外的属性值
					if (curRowData['saveselected'] == 1)
					{
						curChk.attr('checked', 'true'); // 设置所有checkbox被选中}
						jQuery("#jichu_set_table").jqGrid('setRowData', rowIds[k],
						{
							saveselected : 1
						});
					}
					else
					{
						curChk.removeAttr('checked'); // 设置所有checkbox被选中}
						jQuery("#jichu_set_table").jqGrid('setRowData', rowIds[k],
						{
							saveselected : 0
						});
					}
				}

			},
			onSelectRow : function(rowid, status)
			{
				var rowDatas = $("#jichu_set_table").jqGrid('getRowData', rowid);
				if ($("#jichu_set_table").find("input[id='jqg_jichu_set_table_" + rowid + "']")[0].checked)
				{
					jQuery("#jichu_set_table").jqGrid('setRowData', rowid,
					{
						saveselected : 1
					});
				}
				else
				{
					if (rowDatas['description'] == "检索" || rowDatas['description'] == "类别" || rowDatas['description'] == "科室" || rowDatas['description'] == "医生" || rowDatas['description'] == "门诊号" || rowDatas['description'] == "身份证号" || rowDatas['description'] == "姓名" || rowDatas['description'] == "姓别" || rowDatas['description'] == "年龄" || rowDatas['description'] == "出生日期" || rowDatas['description'] == "病人类别" || rowDatas['description'] == "费别" || rowDatas['description'] == "移动电话" || rowDatas['description'] == "急诊" || rowDatas['description'] == "复诊" || rowDatas['description'] == "性别")
					{
						$("#jichu_set_table").find("input[id='jqg_jichu_set_table_" + rowid + "']")[0].disabled = true;
						$("#jichu_set_table").find("input[id='jqg_jichu_set_table_" + rowid + "']")[0].checked = true;

						jQuery("#jichu_set_table").jqGrid('setRowData', rowid,
						{
							saveselected : 0
						});

					}
					else
					{
						jQuery("#jichu_set_table").jqGrid('setRowData', rowid,
						{
							saveselected : 0
						});
					}

				}
			},
			onSelectAll : function(rowid, status)
			{ // rowid 数组
				var ids = jQuery("#jichu_set_table").jqGrid('getDataIDs');
				if (!$("#cb_jichu_set_table")[0].checked)
				{
					for (var i = 0; i < ids.length; i++)
					{
						var cl = ids[i];
						var curRowData = jQuery("#jichu_set_table").jqGrid('getRowData', cl);
						if (curRowData['description'] == "检索" || curRowData['description'] == "类别" || curRowData['description'] == "科室" || curRowData['description'] == "医生" || curRowData['description'] == "门诊号" || curRowData['description'] == "身份证号" || curRowData['description'] == "姓名" || curRowData['description'] == "姓别" || curRowData['description'] == "年龄" || curRowData['description'] == "出生日期" || curRowData['description'] == "病人类别" || curRowData['description'] == "费别" || curRowData['description'] == "移动电话" || curRowData['description'] == "急诊" || curRowData['description'] == "复诊" || curRowData['description'] == "性别")
						{
							$("#jichu_set_table").find("input[id='jqg_jichu_set_table_" + cl + "']")[0].checked = true;
							$("#jichu_set_table").find("input[id='jqg_jichu_set_table_" + cl + "']")[0].disabled = true;
							jQuery("#jichu_set_table").jqGrid('setRowData', cl,
							{
								saveselected : 1
							});

						}
						else
						{
							jQuery("#jichu_set_table").jqGrid('setRowData', cl,
							{
								saveselected : 0
							});
						}
					}
				}
				else
				{
					for (var j = 0; j < ids.length; j++)
					{
						var clj = ids[j];
						var curRowData = jQuery("#jichu_set_table").jqGrid('getRowData', clj);
						jQuery("#jichu_set_table").jqGrid('setRowData', clj,
						{
							saveselected : 1
						});
					}
				}
			},
			loadComplete : function(data)
			{
			}

			});
}
// 校验选中或者是没选中的值
function changesavecanedit(obj, r)
{
	var rows = jQuery("#jichu_set_table").jqGrid('getDataIDs');
	if (obj.checked)
	{
		jQuery("#jichu_set_table").jqGrid('setRowData', r,
		{
			savecanedit : 1
		});
	}
	else
	{
		jQuery("#jichu_set_table").jqGrid('setRowData', r,
		{
			savecanedit : 0
		});
	}
}
function changesavemustinput(obj, r)
{
	var rows = jQuery("#jichu_set_table").jqGrid('getDataIDs');
	if (obj.checked)
	{
		jQuery("#jichu_set_table").jqGrid('setRowData', r,
		{
			savemustinput : 1
		});
	}
	else
	{
		jQuery("#jichu_set_table").jqGrid('setRowData', r,
		{
			savemustinput : 0
		});
	}
}
// 保存页面设置的信息
function savePageInfo()
{
	var index = layer.msg('设置中....',{icon : 16,skin: 'layui-layer-msg16',shade :[0.1, '#393D49'],time : 0});
	var ids = jQuery("#jichu_set_table").jqGrid('getDataIDs');
	for (var j = 0; j < ids.length; j++)
	{
		var cl = ids[j];
		var curRowData = jQuery("#jichu_set_table").jqGrid('getRowData', cl);
		var pvalue = curRowData["saveselected"] + ";" + curRowData["savemustinput"] + ";" + curRowData["savecanedit"];
		jQuery("#jichu_set_table").jqGrid('setRowData', cl,
		{
			pvalue : pvalue
		});
	}
	var rowDatas = $("#jichu_set_table").jqGrid('getRowData');
	var row = JSON.stringify(rowDatas);
	$.ajax(
	{
	type : 'post',
	url :  rootUrl + "/clidoctor/SavedOneUserParameters",
	data :
	{
		'grid2rows' : row
	},
	dataType : "json",
	success : function(data)
	{
		if (data.result == "Success" || data.result == "SUCCESS")
		{
			
			layer.msg('设置中成功',{icon : 1,skin: 'layui-layer-msg1',shade :[0.1, '#393D49'],time : 2000});
			layer.closeAll();
			guahao();

		
		}
	}

	});
	return false;
}
function checkvcj15_1(obj) {
	if ($(obj).attr("id")=="vcj15_1") {
		$("#vcj15").val(1);
	} else {
		$("#vcj15").val(0);
	}
}
//复诊赋值
function checkvac06(obj) {
	if ($(obj).attr("id")=="vac06_1") {
		$("#vac06").val(1);
	} else {
		$("#vac06").val(0);
	}
	
}
//急诊赋值
function checkvac10(obj) {
	if ($(obj).attr("id")=="vac10_1") {
		$("#vac10").val(1);
	} else {
		$("#vac10").val(0);
	}
}

// 加载修改信息
function loadSysParm()
{
	$.ajax(
			{
			type : 'get',
			url : rootUrl + "/clidoctor/selectDataByScriptId?ID=7263",
			dataType : "json",
			success : function(data)
			{
				if (data.result == "Success" || data.result == "SUCCESS")
				{
					json = eval(data); // 数组
					$(".huiyuanxinxi").addClass("hidden");
					$(".danweixinxi").addClass("hidden");
					$(".crmxinxi").addClass("hidden");
					for (var i = 0; i < json.list.length; i++)
					{
						if (json.list[i].saveselected == 1)
						{
							var infoclass = "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno;
							$(".info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno).removeClass("hidden");
							// 必填字段在页面的体现
							if (json.list[i].savemustinput == 1)
							{
							
								$(".info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno).find(".must").removeClass("hidden");
								if ("info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005108" && "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005107" && "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005142" && "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005102" && "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005114" && "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005130" && "info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno != "info100103005126")
								{
									$(".info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno)
											.find(".name").next().addClass("validate[required]");
								}

							}
							else
							{
								$(".info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno).find(".must").addClass("hidden");
							}
						}
						else
						{
							
							$(".info" + json.list[i].productid + json.list[i].programid + json.list[i].paramno)
									.addClass("hidden");
						}

					}
				}
			}
			});
}
